<?php
/**
 * Created by PhpStorm.
 * User: Duyonggao
 * Date: 2016/12/1 0001
 * Time: 下午 4:10
 */

namespace app\controllers;


use app\models\Rules;
use yii\elasticsearch\Exception;
use yii\web\Controller;

class EsController extends Controller
{
    public function actionIndex(){
        for($i=3;$i<100;$i++){
//            $i = 2;
            $rule = new Rules();
            $rule->primaryKey = $i;
            $rule->attributes = [
                'name' => 'test'.$i,
                'url' => 'kjkl'.md5($i.'test'),
                'title' => '测试快乐健康'.md5($i)
            ];
//            var_dump($rule);exit();
            try{
                var_dump($rule->save());
            }catch (Exception $e){
                echo $e->getMessage();
            }
        }
    }
    public function actionShow(){
        $result = Rules::find()->query([
            "match_phrase" => [
                "name" => 'test',
            ]
        ])->all();
//        foreach($result as $vo){
//            echo $vo->url;
//            echo '<br />';
//            echo $vo['url'];
//
//        }
        var_dump($result);
    }
}